/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import Controller.Type;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

public class TypeDAO extends AbstractDAO<Type> {

  public TypeDAO(Connection connect) {
	super(connect);
  }

  @Override
  protected boolean insert(Type obj) {
	throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  }

  @Override
  protected boolean update(Type obj) {
	throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  }

  @Override
  protected boolean delete(Type obj) {
	throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  }

  /**
   * Recup un Type
   * @param id
   * @return Type
   */
  @Override
  protected Type findById(int id) {
	Type type = new Type();
	try {

	  ResultSet res = this.connect.createStatement(
			  ResultSet.TYPE_SCROLL_INSENSITIVE,
			  ResultSet.CONCUR_READ_ONLY).executeQuery("SELECT * FROM type WHERE idT = " + id);

	  if (res.first()) {
		type.setIdT(res.getString(1));
		type.setNomT(res.getString(2));
	  }

	  return type;

	} catch (Exception e) {
	  e.printStackTrace();
	  return null;
	}
  }

  public Map<String, Type> findAll() {
	Map<String, Type> types = new HashMap();
	try {
	  ResultSet result = this.connect.createStatement(
			  ResultSet.TYPE_SCROLL_INSENSITIVE,
			  ResultSet.CONCUR_READ_ONLY).executeQuery("SELECT * FROM type");

	  while (result.next()) {
		Type type = new Type();
		type.setIdT(result.getString(1));
		type.setNomT(result.getString(2));
		types.put(type.getIdT(), type);
	  }
	} catch (Exception e) {
	}
	return types;
  }
}
